package com.zerowidth.moc.web.controller;

import com.zerowidth.db.bean.CollectBean;
import com.zerowidth.db.bean.ProblemBean;
import com.zerowidth.db.bean.TeachBean;
import com.zerowidth.moc.web.auth.annotation.NoToken;
import com.zerowidth.moc.web.bean.MockBean;
import com.zerowidth.moc.web.controller.service.MockService;
import com.zerowidth.moc.web.resp.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/v1")
public class MockController {

    @Autowired
    MockService mockService;

    @NoToken
    @GetMapping("/mock/check")
    public ResponseEntity<ResultBean<Boolean>> check(
            HttpServletRequest request,
            @RequestParam("stat_id") String stat_id,
            @RequestParam("user_id") String user_id,
            @RequestParam("brand") String brand,
            @RequestParam("model") String model,
            @RequestParam(value = "manufacturer", required = false) String manufacturer,
            @RequestParam("android_version") String android_version,
            @RequestParam(value = "app_sign_key", required = false) String app_sign_key_md5) {
        return mockService.check(request, stat_id, user_id, brand, model, manufacturer,
                android_version, app_sign_key_md5);
    }

    @NoToken
    @GetMapping("/mock/check2")
    public ResponseEntity<ResultBean<MockBean>> check(
            HttpServletRequest request,
            @RequestParam("stat_id") String stat_id,
            @RequestParam("user_id") String user_id,
            @RequestParam("brand") String brand,
            @RequestParam("model") String model,
            @RequestParam(value = "manufacturer", required = false) String manufacturer,
            @RequestParam("android_version") String android_version,
            @RequestParam(value = "app_sign_key", required = false) String app_sign_key,
            @RequestParam(value = "longitude", required = true) String longitude,
            @RequestParam(value = "latitude", required = true) String latitude) {
        return mockService.check2(request, stat_id, user_id, brand, model, manufacturer,
                android_version, app_sign_key, longitude, latitude);
    }

    @NoToken
    @GetMapping("/mock/share_award")
    public ResponseEntity<ResultBean<Boolean>> shareAward(
            HttpServletRequest request,
            @RequestParam("stat_id") String stat_id,
            @RequestParam("user_id") String user_id) {
        return mockService.shareAward(stat_id, user_id);
    }

    @NoToken
    @PostMapping("/mock/collect")
    public ResponseEntity<ResultBean<Boolean>> collect(
            HttpServletRequest request,
            @RequestParam("name") String name,
            @RequestParam("stat_id") String stat_id,
            @RequestParam("user_id") String user_id,
            @RequestParam("lat") String lat,
            @RequestParam("lng") String lng,
            @RequestParam("zoom") String zoom) {
        return mockService.collect(request, name, stat_id, user_id, lat, lng, zoom);
    }

    @NoToken
    @DeleteMapping("/mock/collect")
    public ResponseEntity<ResultBean<Boolean>> deleteCollect(
            HttpServletRequest request,
            @RequestParam("id") String id) {
        return mockService.deleteCollect(request, id);
    }

    @NoToken
    @GetMapping("/mock/collect_list")
    public ResponseEntity<ResultBean<List<CollectBean>>> getCollectList(
            HttpServletRequest request,
            @RequestParam("stat_id") String stat_id,
            @RequestParam("user_id") String user_id) {
        return mockService.getCollectList(request, stat_id, user_id);
    }

    @NoToken
    @GetMapping("/mock/teach_list")
    public ResponseEntity<ResultBean<List<TeachBean>>> getTeachList(
            HttpServletRequest request) {
        return mockService.getTeachList(request);
    }

    @NoToken
    @GetMapping("/mock/problem_list")
    public ResponseEntity<ResultBean<List<ProblemBean>>> getProblemList(
            HttpServletRequest request) {
        return mockService.getProblemList(request);
    }



}
